<template>
    <div>
        <div class="search-content">
            <el-form ref="searchForm" :inline="true" :model="searchContent">
                <el-form-item label="供应商：" prop="store_name">
                    <el-input
                        class="search-content-input"
                        v-model="searchContent.store_name"
                        placeholder="供应商"
                    ></el-input>
                </el-form-item>
                <el-form-item label="状态：" prop="status">
                    <el-select clearable v-model="searchContent.status" placeholder="全部">
                        <el-option value="Open" label="开启"></el-option>
                        <el-option value="Close" label="暂停"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="search">搜索</el-button>
                    <el-button type="primary" @click="resetSearchData">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="search-list">
            <el-table :data="goodsList" border :height="oHeight" :fit="true">
                <!-- <el-table-column align="center" type="selection" width="55"></el-table-column> -->
                <el-table-column align="center" prop="ServiceSuppliersID" label="ID" min-width="60"></el-table-column>
                <el-table-column align="center" prop="SuppliersName" label="供应商名称" min-width="160"></el-table-column>
                <el-table-column align="center" prop="ActiveStatus" label="启用状态" min-width="160"></el-table-column>
                <el-table-column
					fixed="right"
                    align="center"
                    prop="isInitiative"
                    label="操作"
                    min-width="160"
                    #default="{row}"
                    class-name="action">
					<div style="color: #5790bb" v-if="row.ActiveStatus==='Open'">
						<span @click="showContent('show',row)">查看</span>
						<el-divider direction="vertical"></el-divider>
                        <span @click="changeStatus(row,'Close')">暂停</span>
                    </div>
					<div style="color: #5790bb" v-else>
						<span @click="showContent('edit',row)">编辑</span>
						<el-divider direction="vertical"></el-divider>
                        <span @click="changeStatus(row,'Open')">开启</span>
                    </div>
                </el-table-column>
            </el-table>
            <div class="bottom">
                <div class="btn-group">
                    <el-button type="primary" class="btn-bottom" @click="showContent('add')">新增</el-button>
                </div>
                <!--分页部分-->
                <div class="paginationOne">
                    <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="searchContent.currentPage"
                        :page-sizes="[10, 20, 50, 100]"
                        :page-size="searchContent.pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total*1"
                    ></el-pagination>
                </div>
            </div>
        </div>
		<edit-drawer ref="editDrawer"></edit-drawer>
    </div>
</template>
<script>
import { resize } from "@/common/js/height.js";
import { dateFormatter, objScreen } from "@/common/js/util";
import editDrawer from './show-edit-drawer';
export default {
	components: { editDrawer },
    data() {
        return {
            goodsList: [],
            oHeight: 800,
            searchContent: {
                currentPage: 1,
                pageSize: localStorage.getItem('pageSize') * 1 || 10,
				order_time: '',
				store_name:'',
				suppliers_name:'',
				status:'',
            },
            searchObj: {},
            total: 0,
        };
    },
    created() {
        this.getListData();
    },
    methods: {
		showContent(row,status){
			this.$refs.editDrawer.show_dialog_fn(row,status)
		},
		changeStatus(row,status){
			this.$http.post("/admin/dataService/index.php?act=merchantSet&op=alterSupplierStatus",{
				id:row.ServiceSuppliersID,
				status,
				servername:row.SuppliersName
			}).then(res=>{
				if(res.code===1){
					row.ActiveStatus = status;
				}else{
					this.$message.error(res.msg);
				}
			}).catch(err=>{
				this.$message.error(err);
			})
		},
        getListData() {
            var data = this.searchObj;
            data.currentPage = this.searchContent.currentPage;
            data.eachNum = this.searchContent.pageSize;
            this.$http.post('/admin/dataService/index.php?act=merchantSet&op=supplierList', data).then((res) => {
                if (res.code === 1) {
                    this.total = res.data.total;
                    this.goodsList = res.data.list;
                    // this._message('success', res.msg);
                    // this.getListData();
                } else {
                    this.total = 0;
                    this.goodsList = [];
                    this._message('error', res.msg);
                }
            }).catch(err => {
                this._message('error', err);
            })
        },
        search() {
            this.searchContent.currentPage = 1;
			let {store_name,status} = this.searchContent;
            this.searchObj = objScreen({
				store_name,
				status
            })
            this.getListData();
        },
        resetSearchData() {
            this.$refs['searchForm'].resetFields();
        },
        handleSizeChange(pageSize) {
            localStorage.setItem('pageSize', pageSize);
            this.searchContent.pageSize = pageSize;
            this.searchContent.currentPage = 1;
            this.getListData();
        },
        handleCurrentChange(page) {
            this.searchContent.currentPage = page;
            this.getListData();
        },
    },
    mounted() {
        resize(this)
    },
};
</script>
<style lang="scss" scoped>
.action span { cursor: pointer; }
.bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.search-content-input {
    width: 200px;
}
</style>